<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/layui/css/layui.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/css/thesame.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/css/footer.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/rightCon.css'" media="all"/>
		<style type="text/css">
			.pop-up{ padding: 15px 30px }
			.pop-title::before{
				content: '';
				display: block;
				width: 4px;
				height: 25px;
				background-color: #1C9399;
				position: absolute;
				left: 0;
				top: 0;
			}
			.btn-con span{ display: inline-block; padding: 0 25px; height: 40px; line-height: 40px; border-radius: 4px; margin: 0 20px; box-sizing: border-box; }
			.btn-con .btn-one{ background-color: #fafafa; border:1px solid #ddd; color:#666 }
			.btn-con .btn-two{ background-color: #1C9399; color: #fff; }
			.btn-bgRed{ background-color: #FA675C; color: #fff }

			/* 公开弹窗 */
			.add-mess-form-border p{ border: 1px solid #ddd; border-radius: 4px; padding: 0 10px;  width: 300px; box-sizing: border-box; }
			/*.add-mess-form-border span{ position: absolute; right: 0; top: 0; width: 50px; height: 33px; text-align: center; border-left: 1px solid #ddd; }
			.add-mess-form-border span img{ width: 20px; }*/
			.add-mess-pos{ position: absolute; right: 0; top: 10px; }

			/* 分页 */
			.layui-table-page{ height: auto; line-height: 32px; padding: 15px; border-top: 1px solid #eee; text-align: right; }
			.layui-table-page > div{ height: auto; }
			.layui-laypage .layui-laypage-curr .layui-laypage-em { background-color: #1C9399; }
			.layui-table-page .layui-laypage a, .layui-table-page .layui-laypage span,.layui-table-page .layui-laypage button, .layui-table-page .layui-laypage input,.layui-table-page select{ height: 32px; line-height: 32px; margin-bottom: 0; box-sizing: border-box; }
			.layui-laypage-em,.layui-table-page .layui-laypage input,.layui-table-page .layui-laypage button, .layui-table-page .layui-laypage input,.layui-laypage select{ border-radius: 6px; }
			.layui-table-page select{ padding: 0 3px; }
			.layui-laypage input:focus,.layui-laypage select:focus{ border-color: #1C9399!important; }
			.number-page{ position: absolute; left: 15px; bottom: 15px; line-height: 32px; }

			.tree-con-box{ height: 100%; overflow: hidden; }
			.tree-con-box .tree-one{ height: 100%; padding:10px 0; margin-right: -20px; overflow: hidden; overflow-y: scroll; }

			.tree-children{ position: relative; display: flex; line-height: 40px; cursor: pointer; }
			.tree-children div:nth-child(1){ overflow: hidden; flex:1.5 }
			.tree-children div:nth-child(1) p{ float: left; }
			.tree-children div:nth-child(1) p img{ display: block; margin:16px 10px 15px 0 }
			.tree-one div.tree-children div.current{ background-color: rgba(28, 147, 153, 0.1); color: #1C9399; }
			.tree-one li div.tree-children div:nth-child(1) p:nth-child(1){ padding-left: 20px; }
			.tree-two li div.tree-children div:nth-child(1) p:nth-child(1){ padding-left: 40px; }
			.tree-three li div.tree-children div:nth-child(1) p:nth-child(1){ padding-left: 60px; }
			.tree-four li div.tree-children div:nth-child(1) p:nth-child(1){ padding-left: 80px; }
			.tree-five li div.tree-children div:nth-child(1) p:nth-child(1){ padding-left: 100px; }


			.add-mess-child > div.add-mess-form{ width: 300px; }
			.add-mess-child > div.add-mess-form > p{ border: 1px solid #ddd; border-radius: 4px; padding: 0 10px; }
			.add-mess-child .tree-con-box{ position:absolute; left: 0; top: 48px; width:300px; padding-bottom: 20px; z-index: 3; background-color: #fff; box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.15); border-radius: 4px; height: 260px; overflow: hidden; z-index: 110; }
			.add-mess-child .tree-con-box .tree-one{ padding:10px 0; margin-right: -20px; overflow: hidden; overflow-y: scroll; }
			.add-mess-child .tree-con-box .tree-children{ line-height: 40px; }
			.add-mess-child .tree-con-box .tree-children div:nth-child(1) p img{ margin: 16px 10px 16px 0; }
			div.jiucanriqisheding{cursor: pointer}
			.add-mess-child > div:nth-child(1){ width: 0; }
		</style>
	</head>

	<body class="layui-layout-body">
	<input id="id" th:value="${orderId}" type="hidden">
	<input id="monthInput" th:value="${month}" type="hidden">
	<input id="nameInput" th:value="${name}" type="hidden">
	<input id="orgIdInput" th:value="${orgId}" type="hidden">
	<input id="orgNameInput" th:value="${orgName}" type="hidden">
	<input id="mealsInput" th:value="${meals}" type="hidden">
	<input id="deliveryFeeInput" th:value="${deliveryFee}" type="hidden">
	<input id="supplyFoodAddress" th:value="${supplyFoodAddress}" type="hidden">
	<input id="monthStrInput" th:value="${monthStr2}" type="hidden">
	<input id="zaocanInput" th:value="${zaocan}" type="hidden">
	<input id="zhongcancanInput" th:value="${zhongcan}" type="hidden">
	<input id="addTypeInput" th:value="${addType}" type="hidden">
	<input id="nowDayInput" th:value="${nowDay}" type="hidden">
		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div class="add-title pad25px"><span class="mr10px" id="resultButton"><img th:src="${#request.getContextPath()}+'/static/img/return_icon.png'"></span><span>订单详情</span></div>
			<div class="new-add-box new-add-box-width bgWhite box-shadows1 border-radius4">
				<div class="new-add-box-scroll">
					<div class="layui-tab layui-tab-time" lay-filter="food_type">
						<div class="layui-form layui-form-position">
							<div class="one">
								<div id="batchOperationDiv" style="display: none;">
									<span class="mr30px one-green green inline-block pl15px pr15px cursor" id="selectDateAllSpan" data-date=""><img th:src="${#request.getContextPath()}+'/static/foodDelivery/img/icon_time_green.png'" class="mr10px">批量日期选择</span>
									<span class="inline-block cursor"><input type="checkbox" lay-filter="getLatelyUsers" lay-skin="primary" title="就餐方式同最近一次"></span>
								</div>
								<!--日期-->
								<nav hidden="hidden" class="time-con time-con-show textCenter bgWhite">
									<div class="time-title">[[${monthStr2}]]</div>
									<div class="time-list">
										<ul class="time-ul-one">
											<li>周一</li>
											<li>周二</li>
											<li>周三</li>
											<li>周四</li>
											<li>周五</li>
											<li>周六</li>
											<li>周日</li>
										</ul>
										<ul class="time-ul-two" id="selectDateAllUl">

										</ul>
									</div>
									<div class="btn-con textCenter border-top1px">
										<span class="btn-one" style="cursor: pointer" id="selectDateAll_qx">取&nbsp;消</span>
										<span class="btn-two" style="cursor: pointer;" id="selectDateAll_qd">确&nbsp;定</span>
									</div>
								</nav>
							</div>
						</div>
						<div>
							<p class="layui-tab-time-title">[[${monthStr}]]</p>
							<ul class="layui-tab-title">
								<li class="layui-this" data-val="1" lay-id="zaocan">午餐</li>
								<li data-val="2" lay-id="wucan">晚餐</li>
							</ul>
						</div>
						<div class="layui-tab-content bgWhite">
							<div class="layui-tab-item layui-show">
								<div class="lh32px overflow add-btn-input">
									<p class="left cursor">
										<span th:if="${addType} != '3'" class="white border-radius4 bgGreen inline-block pl15px pr15px" id="addArchivesUser"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">添加在档人员</span>
										<span th:if="${addType} != '3'" class="white border-radius4 bgGreen inline-block pl15px pr15px mr25px ml25px" id="addNoArchivesUser"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">添加工作人员</span>
										<!--<span class="white border-radius4 bgRed inline-block pl15px pr15px"><img th:src="${#request.getContextPath()}+'/static/img/icon_delete.png'">批量删除</span>-->
									</p>
									<p class="right">
										<span>共有<em class="green fb ml5px mr5px" id="dingcanshuru_zc">0</em>人</span>
									</p>
								</div>
								<article class="layui-article-box">
									<div class="pop-box-scroll">
										<div class="border1px border-radius4 relative table-time">
											<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
										</div>
									</div>
								</article>
							</div>
							<div class="layui-tab-item">
								<div class="lh32px overflow add-btn-input">
									<p class="left cursor">
										<span class="white border-radius4 bgGreen inline-block pl15px pr15px" id="addArchivesUser_wc"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">添加在档人员</span>
										<span class="white border-radius4 bgGreen inline-block pl15px pr15px mr25px ml25px" id="addNoArchivesUser_wc"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">添加工作人员</span>
										<!--<span class="white border-radius4 bgRed inline-block pl15px pr15px"><img th:src="${#request.getContextPath()}+'/static/img/icon_delete.png'">批量删除</span>-->
									</p>
									<p class="right">
										<span>共有<em class="green fb ml5px mr5px" id="dingcanshuru_wc">0</em>人</span>
									</p>
								</div>
								<article class="layui-article-box">
									<div class="pop-box-scroll">
										<div class="border1px border-radius4 relative table-time">
											<table class="layui-hide" id="dataTable_wc" lay-filter="dataTable_wc"></table>
										</div>
									</div>
								</article>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="layui-footer layui-footer-one">
			<div class="btn-con textCenter">
				<span class="btn-one" style="cursor: pointer" id="fanhui_button">返回</span>
				<span class="btn-two" style="cursor: pointer;display: none;" id="save_button">保存</span>
				<span class="btn-two" style="cursor: pointer;display: none;" id="saveAndSubmit_button">保存并上报</span>
			</div>
		</div>
		<script th:src="@{/static/js/jquery-2.1.3.min.js}"></script>
		<script th:src="${#request.getContextPath()}+'/static/layui/layui.js'"></script>
		<script th:src="${#request.getContextPath()}+'/static/js/selectUser.js'"></script>
		<script>
			var basePath = $("input#basePathInput",parent.document).val();
			var dateHtml = "";
			var existingUser = "";
			var existingUser_cz = "";
			var existingUser_wc = "";
			var saveNoUserFlag = true;
			var saveFlag = true;
			var selectUsers = [];
			var data = [];
			var noDataStr = "";
			var zcNodataStr = "";
			var wcNodataStr = "";
			var zcData = [];  //早餐
			var wcData = [];  //午餐
			var clickObj;
			var zcSelectDate = "";
			var wcSelectDate = "";
			var cols = [ //表头
				{
					field: 'id',
					title: '订单编号',
					hide: true
				},
				{
					field: 'user_no',
					title: '用户编号',
					hide: true
				},
				{
					field: 'isSave',
					title: '保存过',
					hide: true
				},
				{
					type: 'numbers',
					title: '序号',
					fixed: 'left',
					width:70
				}, {
					field: 'user_type',
					title: '人员类别',
					templet: function(res){
						if(res.user_type == "1" || res.user_type == 1){
							return "在档";
						}else if(res.user_type == "2" || res.user_type == 2){
							return "非档";
						}if(res.user_type == "3" || res.user_type == 3){
							return "工作人员";
						}
					}
				}, {
					field: 'user_name',
					title: '姓名',
				}, {
					field: 'user_sex',
					title: '性别',
					templet: function(res){
						if(res.user_sex == "1" || res.user_sex == 1){
							return "男";
						}else if(res.user_sex == "2" || res.user_sex == 2){
							return "女";
						}
					}
				}, {
					field: 'age',
					title: '年龄',
				}, {
					field: 'days',
					title: '就餐日期',
					width: 150,
					templet: function(res){
						let html;
						if(res.isSave == "yes"){
							html = "<div class='green time-img-green' data-date='";
						}else{
							html = "<div class='green time-img-green jiucanriqisheding' data-date='";
						}
						if(res.days && res.days != "null"){
							html += res.days;
						}else{
							html += $("span#selectDateAllSpan")[0].dataset.date;
						}
						html += "'>就餐日期设定<span><img src='"+basePath+"/static/foodDelivery/img/icon_time_green.png'></span></div>";
						return html;
					}
				}, {
					field: 'days_count',
					title: '就餐天数',
					/*templet: function(res){
                        //return "<div class='table-form-arrow relative'><p class='food_jiucantianshu'>0</p></div>"
                        if(res.days_count && $.trim(res.days_count) && !"null" != res.days_count){
                            return res.days_count;
                        }else{
                            return "0";
                        }
                    }*/
				}, {
					field: 'subsidy',
					title: '补贴每餐',
					width: 110,
					edit:"text",
					/*templet: function(res){
                        //return "<div class='table-form table-form-arrow relative'><p><input type='text' value='0' placeholder='金额'></p><p class='textCenter'><span><img src='"+basePath+"/static/foodDelivery/img/icon_up.png' alt=''></span><span><img src='"+basePath+"/static/foodDelivery/img/icon_down.png' alt=''></span></p></div>"
                        if(res.subsidy && $.trim(res.subsidy) && !"null" != res.subsidy){
                            return res.subsidy;
                        }else{
                            return "0";
                        }
                    }*/

				}, {
					field: 'meals',
					title: '餐费',
					/*templet: function(res){
                        //return "<div class='table-form-arrow relative'><p class='food_canfei'>"+$("input#mealsInput").val()+"</p></div>"
                        return $("input#mealsInput").val();
                    }*/
				}, {
					field: 'delivery_fee',
					title: '送餐费',
					/*templet: function(res){
                        //return "<div class='table-form-arrow relative'><p class='food_songcanfei'>0</p></div>"
                        if(res.type == "3" || res.type == 3){
                            return $("input#deliveryFeeInput").val();
                        }else{
                            return "0";
                        }
                    }*/
				}, {
					field: 'cost',
					title: '每客单价',
					/*templet: function(res){
                        //return "<div class='table-form-arrow relative'><p class='food_danjia'>"+$("input#mealsInput").val()+"</p></div>"
                        if(res.cost && $.trim(res.cost) && !"null" != res.cost){
                            return res.cost;
                        }else{
                            return $("input#mealsInput").val();
                        }
                    }*/
				}, {
					field: 'type',
					title: '就餐方式',
					width:150,
					templet: function(res){
						let html = "<div class='table-form table-form-select'><select class='eat_type'><option value='1'";
						if(res.type == "1" || res.type == 1){
							html += " selected='selected'";
						}
						html += ">堂吃</option><option value='2'";
						if(res.type == "2" || res.type == 2){
							html += " selected='selected'";
						}
						html += ">分餐点自提</option><option value='3'";
						if(res.type == "3" || res.type == 3){
							html += " selected='selected'";
						}
						html += ">送餐上门</option></select></div>";
						return html;
					}

				}, {
					field: 'address',
					title: '配餐地址',
					width: 200,
					edit:"text",
					/*templet: function(res){
                        //return "<div class='table-form'><input type='text' readonly value='"+$("input#supplyFoodAddress").val()+"' placeholder='请输入配餐地址'></div>"
                        if(res.type == "3" || res.type == 3){
                            if(res.address && $.trim(res.address) && !"null" != res.address){
                                return res.address;
                            }else{
                                return "";
                            }
                        }else{
                            return $("input#supplyFoodAddress").val();
                        }
                    }*/

				}
			];


			//左侧菜单栏
			layui.use(['element', 'table', 'layer',"laydate","form"], function() {
				var element = layui.element;
				var table = layui.table;
				var layer = layui.layer;
				var $ = layui.jquery;
				var laydate = layui.laydate;
				var form = layui.form;

				$("span#resultButton").on("click",function (e) {
					window.location.href="../ordering/index";
				})

				if($("input#addTypeInput").val() != "3" && $("input#addTypeInput").val() != 3){
					cols.push({
						field: 'operation',
						title: '操作',
						width: 200,
						fixed: 'right',
						templet: function(res){
							if($("input#zaocanInput").val() == "yes"){
								if(res.isSave && res.isSave == "yes"){
									if($("input#addTypeInput").val() == "1" || $("input#addTypeInput").val() == 1) {
										return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;display: none' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;' data-id='" + res.user_no + "'>修改</span></div>";
									}else{
										return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;display: none' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
									}
								}else {
									return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;display: none' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
								}
							}else{
								return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;display: none' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;display: none' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
							}
						}
					})
				}

				if(! ($("input#zaocanInput").val() == "yes")){
					$("div#batchOperationDiv").css("display","block");
				}

				form.on('checkbox(getLatelyUsers)',function(data){
					let foodType = $("li.layui-this").data("val") + "";
					if(data.elem.checked==true){
						data.elem.disabled = true;
						$.ajax({
							url:"../orderingRecords/getLatelyUsers",
							type:"post",
							dataType:"json",
							data:{"orgNo":$("input#orgIdInput").val(),"foodType":foodType},
							success:function (result) {
								if(result.code == 200){
									if(result.data && result.data.length > 0) {
										data = result.data;
										$("em#dingcanshuru_zc").text(result.count);
										let tableName = "";
										if("1" == ($("li.layui-this").data("val")+"")){
											tableName = "dataTable"
										}else{
											tableName = "dataTable_wc";
										}
										table.reload(tableName, {
											data:data
										});
									}else{
										ayer.msg("暂无最近一次订餐居民数据失败！")
									}
								}else{
									layer.msg("获取最近一次订餐居民数据失败！")
								}
							}
						});
					}
				});

				if($("input#id").val()){
					$.ajax({
						url:"../orderingRecords/getOrderData",
						type:"post",
						dataType:"json",
						async:false,
						data:{"foodType":"1","month":$("input#monthInput").val(),"orderId":$("input#id").val()},
						success:function (result) {
							if(result.code == 200){
								data = result.data;
								/*data.forEach(function (v,i) {
									existingUser_cz += v.user_no + ",";
								})*/
								result.data.forEach(function (v,i) {
									zcNodataStr += v.user_no + ",";
								})
								noDataStr = zcNodataStr;
								existingUser_cz = zcNodataStr;
								existingUser = existingUser_cz;
								$("em#dingcanshuru_zc").text(result.count);
							}else{
								layer.msg("获取订餐居民数据失败！")
							}
						}
					});

					$.ajax({
						url:"../orderingRecords/getOrderData",
						type:"post",
						dataType:"json",
						async:false,
						data:{"foodType":"2","month":$("input#monthInput").val(),"orderId":$("input#id").val()},
						success:function (result) {
							if(result.code == 200){
								wcData = result.data;
								result.data.forEach(function (v,i) {
									wcNodataStr += v.user_no + ",";
								})
								existingUser_wc = wcNodataStr;
								$("em#dingcanshuru_wc").text(result.count);
							}else{
								layer.msg("获取订居民餐数据失败！")
							}
						}
					});
				}

				if ($("input#zaocanInput").val() == "yes") {
					$("span#save_button").css("display", "none");
					$("span#saveAndSubmit_button").css("display", "none");
					$("div#batchOperationDiv").css("display","none");
				} else {
					$("span#save_button").css("display", "inline-block");
					$("span#saveAndSubmit_button").css("display", "inline-block");
					$("div#batchOperationDiv").css("display","block");
				}

				element.on('tab(food_type)', function(){
					let type = this.getAttribute('lay-id');
					saveFlag = true;
					if(type == "zaocan") {
						wcData = data;
						data = zcData;
						noDataStr = zcNodataStr;
						existingUser = existingUser_cz;
						wcSelectDate = $('span#selectDateAllSpan')[0].dataset.date;
						$('span#selectDateAllSpan')[0].dataset.date = zcSelectDate;
						if ($("input#zaocanInput").val() == "yes") {
							$("span#save_button").css("display", "none");
							$("span#saveAndSubmit_button").css("display", "none");
							$("div#batchOperationDiv").css("display","none");
						} else {
							$("span#save_button").css("display", "inline-block");
							$("span#saveAndSubmit_button").css("display", "inline-block");
							$("div#batchOperationDiv").css("display","block");
						}
					}else{
						zcData = data;
						data = wcData;
						noDataStr = wcNodataStr;
						existingUser = existingUser_wc;
						zcSelectDate = $('span#selectDateAllSpan')[0].dataset.date;
						$('span#selectDateAllSpan')[0].dataset.date = wcSelectDate;
						if($("input#zhongcancanInput").val() == "yes"){
							$("span#save_button").css("display","none");
							$("span#saveAndSubmit_button").css("display","none");
							$("div#batchOperationDiv").css("display","none");
						}else{
							$("span#save_button").css("display","inline-block");
							$("span#saveAndSubmit_button").css("display","inline-block");
							$("div#batchOperationDiv").css("display","block");
						}
					}
				});

				getDateHtml(layer);

				$("span#fanhui_button").on("click",function (e) {
					window.location.href="../ordering/index";
				})

				//第一个实例
				table.render({
					elem: '#dataTable',
					data: data,
					page: false,
					limit: 500, //显示的数量
					id:"dataTable",
					done:function(res, curr, count){
						eatTypeChange();
						setEatDate();
						let tableView = this.elem.next();
						layui.each(res.data, function(i, item) {
							if (item.isSave && item.isSave == 'yes') {
								tableView.find('tr[data-index=' + i + ']').find('td[data-field="subsidy"]')[0].dataset.edit=false;
								tableView.find('tr[data-index=' + i + ']').find('td[data-field="address"]')[0].dataset.edit=false;
								tableView.find('tr[data-index=' + i + ']').find('td select').attr("disabled","disabled");
							}
						})
					},
					cols: [
						cols
					]
				});

				//第二个实例
				table.render({
					elem: '#dataTable_wc',
					data: wcData,
					page: false,
					id:"dataTable_wc",
					limit: 500, //显示的数量
					done:function(res, curr, count){
						eatTypeChange();
						setEatDate();
						let tableView = this.elem.next();
						layui.each(res.data, function(i, item) {
							if (item.isSave && item.isSave == 'yes') {
								tableView.find('tr[data-index=' + i + ']').find('td[data-field="subsidy"]')[0].dataset.edit=false;
								tableView.find('tr[data-index=' + i + ']').find('td[data-field="address"]')[0].dataset.edit=false;
								tableView.find('tr[data-index=' + i + ']').find('td select').attr("disabled","disabled");
							}
						})
					},
					/*cols: [
						[ //表头
						{
							field: 'id',
							title: '订单编号',
							hide: true
						},
						{
							field: 'user_no',
							title: '用户编号',
							hide: true
						},
						{
							field: 'isSave',
							title: '保存过',
							hide: true
						},
						{
							type: 'numbers',
							title: '序号',
							fixed: 'left',
							width:70
						}, {
							field: 'user_type',
							title: '人员类别',
							templet: function(res){
								if(res.user_type == "1" || res.user_type == 1){
									return "在档";
								}else if(res.user_type == "2" || res.user_type == 2){
									return "非档";
								}if(res.user_type == "3" || res.user_type == 3){
									return "工作人员";
								}
							}
						}, {
							field: 'user_name',
							title: '姓名',
						}, {
							field: 'user_sex',
							title: '性别',
							templet: function(res){
								if(res.user_sex == "1" || res.user_sex == 1){
									return "男";
								}else if(res.user_sex == "2" || res.user_sex == 2){
									return "女";
								}
							}
						}, {
							field: 'age',
							title: '年龄',
						}, {
							field: 'days',
							title: '就餐日期',
							width: 150,
							templet: function(res){
								let html;
								if(res.isSave == "yes"){
									html = "<div class='green time-img-green' data-date='";
								}else{
									html = "<div class='green time-img-green jiucanriqisheding' data-date='";
								}
								if(res.days && res.days != "null"){
									html += res.days;
								}else{
									html += $("span#selectDateAllSpan")[0].dataset.date;
								}
								html += "'>就餐日期设定<span><img src='"+basePath+"/static/foodDelivery/img/icon_time_green.png'></span></div>";
								return html;
							}
						}, {
							field: 'days_count',
							title: '就餐天数',
						}, {
							field: 'subsidy',
							title: '补贴每餐',
							width: 110,
							edit:"text"
						}, {
							field: 'meals',
							title: '餐费'
						}, {
							field: 'delivery_fee',
							title: '送餐费'
						}, {
							field: 'cost',
							title: '每客单价'
						}, {
							field: 'type',
							title: '就餐方式',
							width:150,
							templet: function(res){
								let html = "<div class='table-form table-form-select'><select class='eat_type'><option value='1'";
								if(res.type == "1" || res.type == 1){
									html += " selected='selected'";
								}
								html += ">堂吃</option><option value='2'";
								if(res.type == "2" || res.type == 2){
									html += " selected='selected'";
								}
								html += ">分餐点自提</option><option value='3'";
								if(res.type == "3" || res.type == 3){
									html += " selected='selected'";
								}
								html += ">送餐上门</option></select></div>";
								return html;
							}

						}, {
							field: 'address',
							title: '配餐地址',
							width: 200,
							edit:"text"
						}, {
							field: 'operation',
							title: '操作',
							width: 200,
							fixed: 'right',
							templet: function(res){
								//return "<div class='table-list-btn'><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='"+res.user_no+"'>删除</span></div>"
								if($("input#zaocanInput").val() == "yes"){
									if(res.isSave && res.isSave == "yes"){
										return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;display: none' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
									}else {
										return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;display: none' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
									}
								}else{
									return "<div class='table-list-btn'><span class='food_saveUser' lay-event='food_saveUser' style='color: #31A4FF;display: none' data-id='" + res.user_no + "'>保存</span><span class='food_editUser' lay-event='food_editUser' style='color: #1C9399;display: none' data-id='" + res.user_no + "'>修改</span><span class='food_deleteUser' lay-event='food_deleteUser' style='color: #FF3B30;' data-id='" + res.user_no + "'>删除</span></div>";
								}
							}
						}
						]
					]*/
					cols:[cols]
				});

				function eatTypeChange(){
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					$("select.eat_type",$("div[lay-id='"+tableName+"']")).unbind().on("change",function (e) {
						let val = $(this).val();
						if(val && clickObj){
							if(val == "3" || val == 3){
								clickObj.update({delivery_fee: $("input#deliveryFeeInput").val(),type:val,cost:parseFloat(clickObj.data.cost)+parseFloat($("input#deliveryFeeInput").val())});
							}else{
								if(clickObj.data.type == "3" || clickObj.data.type == 3) {
									clickObj.update({
										delivery_fee: "0",
										type: val,
										cost: parseFloat(clickObj.data.cost) - parseFloat($("input#deliveryFeeInput").val())
									});
								}else{
									clickObj.update({
										delivery_fee: "0",
										type: val
									});
								}
							}
							eatTypeChange();
						}
					})
				}

				function setEatDate(){
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					$(".jiucanriqisheding",$("div[lay-id='"+tableName+"']")).unbind().on("click",function (e) {
						let that = this;
						let date = $(that)[0].dataset.date;
						$('.time-con-show').hide();
						layer.open({
							type: 1,
							title: false, //不显示标题栏
							closeBtn: false,
							shade: 0.6,
							//日期
							area: ['340px', ''],
							shade: false,
							id: 'payCons',
							btnAlign: 'c',
							moveType: 1, //拖拽模式，0或者1
							shadeClose: true, //设置允许点遮罩关闭
							content: '<nav class="time-con time-con-show textCenter bgWhite"><div class="time-title">'+$("input#monthStrInput").val()+'</div><div class="time-list"><ul class="time-ul-one"><li>周一</li><li>周二</li><li>周三</li><li>周四</li><li>周五</li><li>周六</li><li>周日</li></ul><ul class="time-ul-two" id="selectDateUl">'+dateHtml+'</ul></div><div class="btn-con textCenter border-top1px"><span class="btn-one" style="cursor: pointer" id="selectDate_qx">取&nbsp;消</span><span class="btn-two" style="cursor: pointer;" id="selectDate_qd">确&nbsp;定</span></div></nav>',
							success: function() {
								//关闭弹层
								$("#selectDate_qx").click(function() {
									layer.closeAll();
								});

								if(date){
									date += "";
									let arr = date.split(",");
									if(arr && arr.length > 0){
										arr.forEach(function (v,i) {
											$("li#date_"+v,$("ul#selectDateUl")).addClass("current");
										})
									}
								}

								$("ul#selectDateUl li.selectDate:not(.notSelect)").on("click",function (e) {
									if($(this).hasClass("current")){
										$(this).removeClass("current");
									}else{
										$(this).addClass("current");
									}
								});

								$('span#selectDate_qd').on("click",function(){
									layer.closeAll();
									let dates = "";
									let count = 0;
									$("ul#selectDateUl li.selectDate.current").each(function (i,v) {
										dates +=  $(this).data("val") + ",";
										count ++;
									})
									if(dates){dates = dates.substring(0,dates.length - 1);}
									$(that)[0].dataset.date = dates;
									clickObj.update({days:dates,days_count:count});
									setEatDate();
								})

							},

						});
					})
				}

				table.on('edit(dataTable)', function(obj){
					let value = obj.value;
					let selector = obj.tr.find('[data-field=' + obj.field + ']');
					let oldtext = $(selector).text();
					if (obj.field == 'subsidy') {
						let reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
						if(!value || !$.trim(value) || value == "null" || value == "undefined"){
							obj.tr.find('td[data-field=subsidy] input').val("0");
							obj.update({ subsidy: "0" });
						}else if (!reg.test(obj.value)) {
							layer.msg('每餐补贴金额格式不正确！');
							obj.tr.find('td[data-field=subsidy] input').val(oldtext);
							obj.update({ subsidy: oldtext });
						}else if (parseFloat(value) > 10 || parseFloat(value) < 0) {
							layer.msg('每餐补贴金额格式必须在0-10元之内！');
							obj.tr.find('td[data-field=subsidy] input').val(oldtext);
							obj.update({ subsidy: oldtext });
						}else{
							obj.update({cost:(parseFloat(obj.data.cost) + parseFloat(oldtext) - parseFloat(value))+"",meals:(parseFloat(obj.data.meals) + parseFloat(oldtext) - parseFloat(value))+""})
						}

					}else if(obj.field == "address"){
						if(obj.data.type == '3' || obj.data.type == 3) {
							if (!value || !$.trim(value) || value == "null" || value == "undefined") {
								layer.msg('送餐地址不能为空！');
								obj.tr.find('td[data-field=address] input').val(oldtext);
								obj.update({address: oldtext});
							} else if (value.length > 50) {
								layer.msg('送餐地址最大支持50个字符！');
								obj.tr.find('td[data-field=address] input').val(oldtext);
								obj.update({address: oldtext});
							}
						}else{
							layer.msg('仅送餐上门支持更改配餐地址！');
							obj.tr.find('td[data-field=address] input').val(oldtext);
							obj.update({address: oldtext});
						}
					}
				});

				table.on('row(dataTable)', function(obj){
					clickObj = obj;
				});

				table.on('tool(dataTable)', function(obj){
					var layEvent = obj.event;
					if(layEvent === 'food_deleteUser'){ //删除
						layer.confirm('确认删除该条数据吗？', function(index){
							layer.close(index);
							if(obj.data.id && $.trim(obj.data.id)){
								let deleteLayer = layer.msg('删除中...', {
									icon: 16
									,shade: 0.01,
									time:50000000
								});
								$.ajax({
									url:"../orderingRecords/delete",
									type:"post",
									dataType:"json",
									data:{"id":obj.data.id},
									success:function (result) {
										layer.close(deleteLayer);
										layer.msg(result.msg);
									}
								})
							}
							existingUser = existingUser.replace(obj.data.user_no+",","");
							$.each(data,function (i,v) {
								if(v.user_no == obj.data.user_no){
									data.splice(i, 1);
									return false;
								}
							})
							obj.del();
						});
					}else if(layEvent === 'food_editUser'){ //修改
						if($("input#addTypeInput").val() == "2" || $("input#addTypeInput").val() == 2) {
							obj.tr.find('td[data-field="subsidy"]').data('edit', true);
							obj.tr.find('td[data-field="address"]').data('edit', true);
							obj.tr.find('td select').removeAttr("disabled");
						}
						$(".jiucanriqisheding",$("div[lay-id='dataTable']")).unbind();
						obj.tr.find('td[data-field="days"] div.time-img-green').addClass('jiucanriqisheding');
						setEatDate();
						obj.tr.find('td span.food_editUser').css("display","none");
						obj.tr.find('td span.food_saveUser').css("display","inline");
					}else if(layEvent === 'food_saveUser'){ //保存
						if(obj.data.days && obj.data.address) {
							if ($("input#addTypeInput").val() == "2" || $("input#addTypeInput").val() == 2) {
								obj.tr.find('td').data('edit', false);
								obj.tr.find('td[data-field="subsidy"]').data('edit', false);
								obj.tr.find('td[data-field="address"]').data('edit', false);
								obj.tr.find('td select').attr("disabled", "disabled");
							}
							$(".jiucanriqisheding",$("div[lay-id='dataTable']")).unbind();
							obj.tr.find('td[data-field="days"] div.time-img-green').removeClass('jiucanriqisheding');
							setEatDate();
							obj.tr.find('td span.food_saveUser').css("display", "none");
							obj.tr.find('td span.food_editUser').css("display", "inline");
							if ($("input#addTypeInput").val() == "1" || $("input#addTypeInput").val() == 1) {
								obj.tr.find('td span.food_deleteUser').remove();
							}
						}
						if(!(obj.data.days && $.trim(obj.data.days))){
							layer.msg("就餐日期不能为空！");
						}else if(!(obj.data.address && $.trim(obj.data.address))){
							layer.msg("配餐地址不能为空！");
						}else{
							let foodType = $("li.layui-this").data("val") + "";
							let saveLayer = layer.msg('保存中...', {
								icon: 16
								,shade: 0.01,
								time:50000000
							});
							$.ajax({
								url:"../orderingRecords/save",
								type:"post",
								dataType:"json",
								data:{"data":JSON.stringify(obj.data),"month":$("input#monthInput").val(),"name":$("input#nameInput").val()
									,"orgId":$("input#orgIdInput").val(),"supplyFoodAddress":$("input#supplyFoodAddress").val(),"foodType":foodType,"orderId":$("input#id").val()},
								success:function (result) {
									layer.close(saveLayer);
									layer.msg(result.msg);
									if(result.code == 200){
										obj.update({
											id:result.data.id,
											isSave:"yes"
										})

										let tableName = "";
										if("1" == ($("li.layui-this").data("val")+"")){
											tableName = "dataTable"
										}else{
											tableName = "dataTable_wc";
										}
										let tableData = table.cache[tableName];
										data = tableData.slice(0);
									}
								}
							})
						}
					}
				});

				table.on('edit(dataTable_wc)', function(obj){
					let value = obj.value;
					let selector = obj.tr.find('[data-field=' + obj.field + ']');
					let oldtext = $(selector).text();
					if (obj.field == 'subsidy') {
						let reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
						if(!value || !$.trim(value) || value == "null" || value == "undefined"){
							obj.tr.find('td[data-field=subsidy] input').val("0");
							obj.update({ subsidy: "0" });
						}else if (!reg.test(obj.value)) {
							layer.msg('每餐补贴金额格式不正确！');
							obj.tr.find('td[data-field=subsidy] input').val(oldtext);
							obj.update({ subsidy: oldtext });
						}else if (parseFloat(value) > 10 || parseFloat(value) < 0) {
							layer.msg('每餐补贴金额格式必须在0-10元之内！');
							obj.tr.find('td[data-field=subsidy] input').val(oldtext);
							obj.update({ subsidy: oldtext });
						}else{
							obj.update({cost:(parseFloat(obj.data.cost) + parseFloat(oldtext) - parseFloat(value))+"",meals:(parseFloat(obj.data.meals) + parseFloat(oldtext) - parseFloat(value))+""})
						}

					}else if(obj.field == "address"){
						if(obj.data.type == '3' || obj.data.type == 3) {
							if (!value || !$.trim(value) || value == "null" || value == "undefined") {
								layer.msg('送餐地址不能为空！');
								obj.tr.find('td[data-field=address] input').val(oldtext);
								obj.update({address: oldtext});
							} else if (value.length > 50) {
								layer.msg('送餐地址最大支持50个字符！');
								obj.tr.find('td[data-field=address] input').val(oldtext);
								obj.update({address: oldtext});
							}
						}else{
							layer.msg('仅送餐上门支持更改配餐地址！');
							obj.tr.find('td[data-field=address] input').val(oldtext);
							obj.update({address: oldtext});
						}
					}
				});

				table.on('row(dataTable_wc)', function(obj){
					clickObj = obj;
				});

				table.on('tool(dataTable_wc)', function(obj){
					var layEvent = obj.event;
					if(layEvent === 'food_deleteUser'){ //删除
						layer.confirm('确认删除该条数据吗？', function(index){
							layer.close(index);
							if(obj.data.id && $.trim(obj.data.id)){
								let deleteLayer = layer.msg('删除中...', {
									icon: 16
									,shade: 0.01,
									time:50000000
								});
								$.ajax({
									url:"../orderingRecords/delete",
									type:"post",
									dataType:"json",
									data:{"id":obj.data.id},
									success:function (result) {
										layer.close(deleteLayer);
										layer.msg(result.msg);
									}
								})
							}
							existingUser = existingUser.replace(obj.data.user_no+",","");
							$.each(data,function (i,v) {
								if(v.user_no == obj.data.user_no){
									data.splice(i, 1);
									return false;
								}
							})
							obj.del();
						});
					}else if(layEvent === 'food_editUser'){ //修改
						if($("input#addTypeInput").val() == "2" || $("input#addTypeInput").val() == 2) {
							obj.tr.find('td[data-field="subsidy"]').data('edit', true);
							obj.tr.find('td[data-field="address"]').data('edit', true);
							obj.tr.find('td select').removeAttr("disabled");
						}
						$(".jiucanriqisheding",$("div[lay-id='dataTable_wc']")).unbind();
						obj.tr.find('td[data-field="days"] div.time-img-green').addClass('jiucanriqisheding');
						setEatDate();
						obj.tr.find('td span.food_editUser').css("display","none");
						obj.tr.find('td span.food_saveUser').css("display","inline");
					}else if(layEvent === 'food_saveUser'){ //保存
						if(obj.data.days && obj.data.address){
							/*obj.tr.find('td').data('edit', false);
							obj.tr.find('td[data-field="subsidy"]').data('edit', false);
							obj.tr.find('td[data-field="address"]').data('edit', false);
							obj.tr.find('td[data-field="days"] div.time-img-green').removeClass('jiucanriqisheding');
							setEatDate();
							obj.tr.find('td select').attr("disabled","disabled");
							obj.tr.find('td span.food_saveUser').css("display","none");
							obj.tr.find('td span.food_editUser').css("display","inline");*/
							if($("input#addTypeInput").val() == "2" || $("input#addTypeInput").val() == 2) {
								obj.tr.find('td').data('edit', false);
								obj.tr.find('td[data-field="subsidy"]').data('edit', false);
								obj.tr.find('td[data-field="address"]').data('edit', false);
								obj.tr.find('td select').attr("disabled","disabled");
							}
							$(".jiucanriqisheding",$("div[lay-id='dataTable_wc']")).unbind();
							obj.tr.find('td[data-field="days"] div.time-img-green').removeClass('jiucanriqisheding');
							setEatDate();
							obj.tr.find('td span.food_saveUser').css("display","none");
							obj.tr.find('td span.food_editUser').css("display","inline");
							if ($("input#addTypeInput").val() == "1" || $("input#addTypeInput").val() == 1) {
								obj.tr.find('td span.food_deleteUser').remove();
							}
						}

						if(!(obj.data.days && $.trim(obj.data.days))){
							layer.msg("就餐日期不能为空！");
						}else if(!(obj.data.address && $.trim(obj.data.address))){
							layer.msg("配餐地址不能为空！");
						}else{
							let foodType = $("li.layui-this").data("val") + "";
							let saveLayer = layer.msg('保存中...', {
								icon: 16
								,shade: 0.01,
								time:50000000
							});
							$.ajax({
								url:"../orderingRecords/save",
								type:"post",
								dataType:"json",
								data:{"data":JSON.stringify(obj.data),"month":$("input#monthInput").val(),"name":$("input#nameInput").val()
									,"orgId":$("input#orgIdInput").val(),"supplyFoodAddress":$("input#supplyFoodAddress").val(),"foodType":foodType,"orderId":$("input#id").val()},
								success:function (result) {
									layer.close(saveLayer);
									layer.msg(result.msg);
									if(result.code == 200){
										obj.update({
											id:result.data.id,
											isSave:"yes"
										})

										let tableName = "";
										if("1" == ($("li.layui-this").data("val")+"")){
											tableName = "dataTable"
										}else{
											tableName = "dataTable_wc";
										}
										let tableData = table.cache[tableName];
										data = tableData.slice(0);
									}
								}
							})
						}
					}
				});

				$("span#save_button").on("click",function (e) {
					let tableName = "";
					let inputName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
						inputName = "zaocanInput";
					}else{
						tableName = "dataTable_wc";
						inputName = "zhongcancanInput";
					}
					let tableData = table.cache[tableName];
					save(tableData,"1",inputName);
				})

				$("span#saveAndSubmit_button").on("click",function (e) {
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					let tableData = table.cache[tableName];
					save(tableData,"2","zaocanInput");
				})

				$("span#addArchivesUser,span#addArchivesUser_wc").on("click",function (e) {
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					let tableData = table.cache[tableName];
					let copyData = tableData.slice(0);
					data = tableData.slice(0);
					SelectUser.initSelectUser(layer,table,"1",copyData,selectUserConfirm,wcNodataStr);
				})

				$("span#addNoArchivesUser,span#addNoArchivesUser_wc").on("click",function (e) {
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					layer.open({
						type: 1,
						title: false, //不显示标题栏
						closeBtn: false,
						area: ['900px', '600px'],
						shade: 0.6,
						id: 'payCons',
						btnAlign: 'c',
						moveType: 1, //拖拽模式，0或者1
						shadeClose: true, //设置允许点遮罩关闭
						content: '<div id="pop-con"><div class="pop-up"><div><div class="pop-title relative overflow mb15px"><span class="ml15px">添加工作人员</span><p class="right close_nouser_layer" style="cursor: pointer"><img src="'+basePath+'/static/img/close_icon.png" class="block pop-close"><p></div><div class="pop-form pop-form-width mb30px"><div class="lh32px overflow add-btn-input mt20px mb20px"><span class="white border-radius4 bgGreen inline-block pl15px pr15px" style="cursor: pointer" id="addArchivesUserRow"><img src="'+basePath+'/static/img/button_add.png">添加</span></div><article class="pop-box"><div class="pop-box-scroll"><div class="border1px border-box border-radius4 relative table-time"><table class="layui-hide" id="noArchivesUserTable" lay-filter="noArchivesUserTable"></table></div></div></article></div><div class="btn-con btn-con-position textCenter"><span class="btn-one close_nouser_layer" style="cursor: pointer">取&nbsp;消</span><span class="btn-two" id="sumbit_nouser_layer" style="cursor: pointer">提&nbsp;交</span></div></div></div></div>',
						success: function() {
							//关闭弹层
							$(".close_nouser_layer").on("click",function() {
								layer.closeAll();
							});

							//添加非档人员
							let noArchivesUserTable = table.render({
								elem: '#noArchivesUserTable',
								data: [{
									"type": "2",
									"name": "",
									"sex": "1",
									"birth_date": ""
								} ],
								id:"noArchivesUserTable",
								page: false,
								cols: [
									[ {
										field: 'type',
										title: '类别',
										width: 150,
										templet: function(res){
											//let html = "<div class='table-form table-form-select'><select class='noArchivesUser_type'><option value='2'";
											let html = "<div class='table-form table-form-select'><select class='noArchivesUser_type'><option value='3'";
											/*if(res.type == "2" || res.type == 2){
												html += " selected='selected'"
											}
											html += ">非档</option><option value='3'";*/
											if(res.type == "3" || res.type == 3){
												html += " selected='selected'"
											}
											html +=">工作人员</option></select></div>"
											return html;
										}
									}, {
										field: 'name',
										title: '姓名',
										templet: function(res){
											let html = "<div class='table-form'><input class='noArchivesUser_name' type='text' max='10' placeholder='请输入姓名'";
											if(res.name){
												html += " value = '"+res.name+"'"
											}
											html += "></div>";
											return html;
										}
									}, {
										field: 'sex',
										title: '性别',
										width: 110,
										templet: function(res){
											//return "<div class='table-form table-form-select'><select class='noArchivesUser_sex'><option value='1'></option><option value='2'>女</option></select></div>"
											let html = "<div class='table-form table-form-select'><select class='noArchivesUser_sex'><option value='1'";
											if(res.sex == "1" || res.sex == 1){
												html += " selected='selected'"
											}
											html += ">男</option><option value='2'";
											if(res.sex == "2" || res.sex == 2){
												html += " selected='selected'"
											}
											html +=">女</option></select></div>"
											return html;
										}

									}, {
										field: 'birth_date',
										title: '出生日期',
										width: 200,
										templet: function(res){
											let html = "<div class='table-form table-form-arrow relative'><p><input class='noArchivesUser_bd' readonly type='text' placeholder='请选择出生日期'";
											if(res.birth_date){
												html += " value='"+res.birth_date+"'";
											}
											html += "></p></div>"
											return html;
										}

									},  {
										field: 'operation',
										title: '操作',
										width: 100,
										fixed: 'right',
										templet: function(res){
											return "<div class='table-list-btn'><span lay-event='del'>删除</span></div>"
										}
									}
									]
								],
								done:function (e) {
									noArchivesUserInitClick();
								}
							});
							table.on('tool(noArchivesUserTable)', function(obj){
								let layEvent = obj.event;

								if(layEvent === 'del'){ //删除
									layer.confirm('确认删除该条数据吗？', function(index){
										obj.del();
										layer.close(index);
									});
								}
							});
							$("#addArchivesUserRow").on("click",function (e) {
								let obj = {
									"type": "2",
									"name": "",
									"sex": "1",
									"birth_date": ""
								};
								//let cbList = table.cache.noArchivesUserTable;
								let cbList = [];
								$("div[lay-id='noArchivesUserTable'] > div > div.layui-table-main table tr").each(function (i,v) {
									let d = {};
									$("td",$(this)).each(function (ii,vv) {
										d[$(this)[0].dataset.field] = $(this)[0].dataset.content;
									})
									cbList.push(d);
								})
								cbList.push(obj);
								table.reload("noArchivesUserTable", {
									data: cbList,
								})
							});
							$("#sumbit_nouser_layer").on("click",function (e) {
								let flag = true;
								let cbList = [];
								$("div[lay-id='noArchivesUserTable'] > div > div.layui-table-main table tr").each(function (i,v) {
									if(flag) {
										let d = {};
										$("td", $(this)).each(function (ii, vv) {
											let field = $(this)[0].dataset.field;
											if("operation" != field) {
												let value = $(this)[0].dataset.content;
												if (value && $.trim(value)) {
													d[$(this)[0].dataset.field] = value;
												} else {
													flag = false;
													return false;
												}
											}else{
												d["age"] = getAge(d["birth_date"]);
											}
										})
										cbList.push(d);
									}else{
										return false;
									}
								})
								if(flag){
									if(saveNoUserFlag){
										saveNoUserFlag = false;
										let jzLayer = layer.msg('加载中...', {
											icon: 16
											,shade: 0.01,
											time:50000000
										});
										$.ajax({
											url:"../noArchivesUser/save",
											type:"post",
											dataType:"json",
											async:false,
											data:{"data":JSON.stringify(cbList)},
											success:function (result) {
												layer.close(jzLayer);
												saveNoUserFlag = true;
												if(result.code == 200){
													let tableData = table.cache[tableName];
													data = tableData.slice(0);
													if(result.data && result.data.length > 0){
														result.data.forEach(function (v,i) {
															if(! v.id){v.id = "";}
															let allDate = $('span#selectDateAllSpan')[0].dataset.date;
															if(allDate){
																if(! v.days){v.days = allDate;}
																if(! v.days_count){v.days_count = allDate.split(",").length;}
															}else{
																if(! v.days){v.days = "";}
																if(! v.days_count){v.days_count = "0";}
															}
															if(! v.subsidy){v.subsidy = "0";}
															if(! v.isSave){v.isSave = "no";}
															if(! v.meals){v.meals = $("input#mealsInput").val();}
															if(! v.delivery_fee){v.delivery_fee = "0";}
															if(! v.cost){v.cost = $("input#mealsInput").val();}
															if(! v.address){v.address = $("input#supplyFoodAddress").val();}
															if(! v.type){v.type = "1";}
															existingUser += v.user_no + ",";
															data.push(v);
														})
													}
													table.reload(tableName, {
														data:data
													});
													layer.closeAll();
												}else{
													layer.msg(result.msg);
												}
											}
										})
									}
								}else{
									layer.msg("请将用户信息填写完整！")
								}
							})
							function noArchivesUserInitClick() {
								$("input.noArchivesUser_bd").each(function (i,v) {
									let that = this;
									laydate.render({
										elem: that
										,max:getCurrDate()
										,done: function(value){
											$(that).parent().parent().parent().parent()[0].dataset.content=value;
										}
									});
								});

								$("select.noArchivesUser_type").unbind().on("change",function (e) {
									let val = $(this).val();
									$(this).parent().parent().parent()[0].dataset.content=val;
								})
								$("input.noArchivesUser_name").unbind().on("input propertychange",function (e) {
									let val = $(this).val();
									$(this).parent().parent().parent()[0].dataset.content=val;
								})
								$("select.noArchivesUser_sex").unbind().on("change",function (e) {
									let val = $(this).val();
									$(this).parent().parent().parent()[0].dataset.content=val;
								})
							}
						}
					});
				})

				$('span#selectDateAllSpan').on("click",function(){
					layer.closeAll();
					let date = $(this)[0].dataset.date;
					if(! ($('.time-con-show').is(":visible"))){
						$("ul#selectDateAllUl li.selectDate").removeClass("current");
						if(date){
							date += "";
							let arr = date.split(",");
							if(arr && arr.length > 0){
								arr.forEach(function (v,i) {
									$("li#date_"+v,$("ul#selectDateAllUl")).addClass("current");
								})
							}
						}
					}
					$('.time-con-show').slideToggle(300);
				})

				$('span#selectDateAll_qx').on("click",function(){
					$('.time-con-show').hide();
				})

				$('span#selectDateAll_qd').on("click",function(){
					$('.time-con-show').hide();
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					let dates = "";
					let count = 0;
					$("ul#selectDateAllUl li.selectDate.current").each(function (i,v) {
						dates +=  $(this).data("val") + ",";
						count ++;
					})
					if(dates){dates = dates.substring(0,dates.length - 1);}
					$('span#selectDateAllSpan')[0].dataset.date = dates;
					$(".jiucanriqisheding",$("div[lay-id='"+tableName+"']")).each(function (e) {
						$(this)[0].dataset.date = dates;
					})
					let tableData = table.cache[tableName];
					if(tableData && tableData.length > 0){
						tableData.forEach(function (v,i) {
							v.days=dates;
							v.days_count=count;
						})
						table.cache[tableName] = tableData;
					}
					table.reload(tableName, {
						data:tableData
					});
				})

				function selectUserConfirm() {
					let tableName = "";
					if("1" == ($("li.layui-this").data("val")+"")){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}
					let users = SelectUser.selectUserList;
					let userStr = "";
					if(users && users.length > 0){
						users.forEach(function (v,i) {
							if(! v.id){v.id = "";}
							let allDate = $('span#selectDateAllSpan')[0].dataset.date;
							if(allDate){
								if(! v.days){v.days = allDate;}
								if(! v.days_count){v.days_count = allDate.split(",").length;}
							}else{
								if(! v.days){v.days = "";}
								if(! v.days_count){v.days_count = "0";}
							}
							if(! v.subsidy){v.subsidy = "0";}
							if(! v.isSave){v.isSave = "no";}
							if(! v.meals){v.meals = $("input#mealsInput").val();}
							if(! v.delivery_fee){v.delivery_fee = "0";}
							if(! v.cost){v.cost = $("input#mealsInput").val();}
							if(! v.address){v.address = $("input#supplyFoodAddress").val();}
							if(! v.type){v.type = "1";}
							userStr += v.user_no + ",";
							if(! (existingUser.indexOf(v.user_no) != -1)){
								existingUser += v.user_no + ",";
								data.push(v);
							}

						})
						if(data && data.length > 0){
							for(let i=data.length - 1 ; i >= 0 ; i--){
								if(data[i].user_type_code && parseInt(data[i].user_type_code) == 1 && ! (userStr.indexOf(data[i].user_no) != -1)){
									data.splice(i,1);
									existingUser = existingUser.replace(data[i].user_no + ",","");
								}
							}
						}
					}
					if("1" == ($("li.layui-this").data("val")+"")){
						$("em#dingcanshuru_zc").text(data.length);
					}else{
						$("em#dingcanshuru_wc").text(data.length);
					}
					table.reload(tableName, {
						data:data
					});
				}

				function save(tableData,reportingStauts,eventStr) {
					let tableName = "";
					let foodType = $("li.layui-this").data("val") + "";
					if("1" == foodType){
						tableName = "dataTable"
					}else{
						tableName = "dataTable_wc";
					}

					var falg = true;
					tableData.forEach(function (v,i) {
						if(!(v.days && $.trim(v.days) && v.days != "null" && v.days != "undefined")){
							falg = false;
						}
					})
					if(! falg){
						layer.msg("就餐日期不能为空！")
						return false;
					}
					if(tableData && tableData.length > 0){
						if(saveFlag){
							saveFlag = false;
							let saveLayer = layer.msg('保存中...', {
								icon: 16
								,shade: 0.01
								,time:50000000
							});
							$.ajax({
								url:"../orderingRecords/saveNextMonthData",
								type:"post",
								dataType:"json",
								data:{"data":JSON.stringify(tableData),"month":$("input#monthInput").val(),"name":$("input#nameInput").val()
									,"orgId":$("input#orgIdInput").val(),"supplyFoodAddress":$("input#supplyFoodAddress").val(),"foodType":foodType,"reportingStauts":reportingStauts,"orderId":$("input#id").val()},
								success:function (result) {
									layer.close(saveLayer);
									layer.msg(result.msg);
									if(result.code == 200){
										$("input#"+eventStr).val("yes");
										$("input#id").val(result.data[0].orderId);
										$("span#save_button").css("display","none");
										$("span#saveAndSubmit_button").css("display","none");
										data = result.data;
										console.info(data);
										table.reload(tableName, {
											data:data
										});
									}else{
										saveFlag = true;
									}
								},
								error:function (e) {
									saveFlag = true;
								}
							});
						}
					}
				}
			});

			function getDateHtml(layer) {
				dateHtml = "";
				var data = {};
				if($("input#id").val()){
					data.id = $("input#id").val();
				}
				$.ajax({
					url:"../orderingRecords/getMonthDate",
					type:"post",
					dataType:"json",
					data:data,
					async:false,
					success:function (result) {
						if(result.code == 200){
							if(result.data && result.data.length > 0){
								for(let j = 0 ; j < parseInt(result.count) ; j++){
									dateHtml += "<li></li>";
								}
								let type = $("input#addTypeInput").val();
								if(type == "1" || type == 1) {
									let nowDay = parseInt($("input#nowDayInput").val()) + 1;
									result.data.forEach(function (v, i) {
										if(parseInt(v) <= nowDay) {
											dateHtml += "<li id='date_" + v + "' data-val='" + v + "' class='selectDate notSelect'>" + v + "</li>";
										}else{
											dateHtml += "<li id='date_" + v + "' data-val='" + v + "' class='selectDate'>" + v + "</li>";
										}
									})
								}else{
									result.data.forEach(function (v, i) {
										dateHtml += "<li id='date_" + v + "' data-val='" + v + "' class='selectDate'>" + v + "</li>";
									})
								}
							}
							$("ul#selectDateAllUl").html(dateHtml);
							$("ul#selectDateAllUl li.selectDate:not(.notSelect)").on("click",function (e) {
								if($(this).hasClass("current")){
									$(this).removeClass("current");
								}else{
									$(this).addClass("current");
								}
							});
						}else{
							layer.msg(result.msg);
						}
					}
				})
			}

			function getAge(strAge) {
				var birArr = strAge.split("-");
				var birYear = birArr[0];
				var birMonth = birArr[1];
				var birDay = birArr[2];

				d = new Date();
				var nowYear = d.getFullYear();
				var nowMonth = d.getMonth() + 1; //记得加1
				var nowDay = d.getDate();
				var returnAge;

				if (birArr == null) {
					return false
				};
				var d = new Date(birYear, birMonth - 1, birDay);
				if (d.getFullYear() == birYear && (d.getMonth() + 1) == birMonth && d.getDate() == birDay) {
					if (nowYear == birYear) {
						returnAge = 0; //
					} else {
						var ageDiff = nowYear - birYear; //
						if (ageDiff > 0) {
							if (nowMonth == birMonth) {
								var dayDiff = nowDay - birDay; //
								if (dayDiff < 0) {
									returnAge = ageDiff - 1;
								} else {
									returnAge = ageDiff;
								}
							} else {
								var monthDiff = nowMonth - birMonth; //
								if (monthDiff < 0) {
									returnAge = ageDiff - 1;
								} else {
									returnAge = ageDiff;
								}
							}
						} else {
							return  "0"; //返回-1 表示出生日期输入错误 晚于今天
						}
					}
					return returnAge;
				} else {
					return ("0");
				}
			}

			function getCurrDate() {
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth()+1;
				var day = date.getDate();
				return (year+'-'+month+'-'+day);
			}

		</script>
	</body>

</html>
